package controllers;


import com.avaje.ebean.Ebean;
import com.avaje.ebean.Query;
import com.avaje.ebean.RawSql;
import com.avaje.ebean.RawSqlBuilder;
import models.B_Customer;
import models.B_Order;
import play.mvc.Result;

import java.util.List;

/**
 * Created by Administrator on 2016/1/12.
 */
public class EbeanController extends BaseController {
    public static Result test(){

        String sql ="select o.id ,o.customer_id, c.name , sum(price) as price from b_order o join b_customer c on o.customer_id = c.id group by customer_id";
        RawSql rawSql = RawSqlBuilder.parse(sql)
                .columnMapping("c.name","customer.name")
                .columnMapping("o.customer_id","customer.id")
                .columnMapping("o.id","id")
                .create();
        Query<B_Order> query = Ebean.find(B_Order.class);
        List<B_Order> orderList = query.setRawSql(rawSql).findList();

        return ajaxSuccess("ok");
    }

    public static Result createTestData(){
        B_Order.DeleteTestData();
        B_Customer.DeleteTestData();

        B_Customer.CreateTestData();
        B_Order.CreateTestData();
        return ajaxSuccess("ok");
    }

}
